<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	
	<script>
		class Promise2{
			constructor(fn){
				let _this = this;
				this._succ = null;
				this._erro = null;

				this.status = '';

				this.queen = [];


				fn(function(...arg){
					_this._succ = arg;
					_this.status = 'succ';
					_this.queen.forEach(json=>{
						json.fn1(...arg)
					});

				},function(...arg){
					_this._erro = arg;
					_this.status = 'erro';
					_this.queen.forEach(json=>{
						json.fn2(...arg);
					});	
				});
			}
			then(fn1,fn2){
				if(this.status == 'succ'){
					fn1(...this._succ)
				}else if(this.status =='erro'){
					fn2(...this._erro)
				}else{
					this.queen.push({fn1,fn2});
				}
			}
		}
		Promise2.all = function(arr){
			let tem = [];
			return new Promise2(function(resole,reject){

				let i=0;
				next();
				function next(){
					arr[i].then(function(res){
						tem.push(res);

						i++;
						if(i==arr.length){
							resolve(tem);
						}else{
							reject(arr)
						}
					},function(){

					})
				}
			})	
		}
		let p = new Promise2(function(resolve,reject){
			// $.ajax({url:'1.js'},dataType:'json').then()
			setTimeout(function(){
				resolve(12)
			},500)
		})
		p.then(function(num){
			alert(num)
		},function(){
			alert("失败")
		})
		// Promise2.all([
		// 	$.ajax(url:'1.js',dataType:'json'),
		// 	$.ajax(url:'1.js',dataType:'json')
		// ]).then(suc=>{
		// 	alert('succese')
		// },err=>{
		// 	alert('error')
		// })
	</script>
</head>
<body>
	
</body>
</html>